<template>
  <div class="wrapper">
    <div class="theme">
      <h1 style="font-size: 18px; font-weight: bold; margin-bottom: 15px;">基础信息配置</h1>
      <a-form :label-col="{ span: 5 }" :wrapper-col="{ span: 10 }">
        <a-form-item label="*年份">
          <a-input v-model="baseConfig.year" placeholder="配置新生大数据使用年份" style="width: 250px;" />
        </a-form-item>
        <a-form-item label="*信息栏跳转">
          <a-input v-model="baseConfig.promote.label" placeholder="配置用户信息栏跳转内容，建议5字以内" style="width: 300px;" />
        </a-form-item>
        <a-form-item label="*链接地址">
          <a-input v-model="baseConfig.promote.link" placeholder="配置用户信息栏链接地址" style="width: 350px;" />
        </a-form-item>
        <a-form-item label="大数据推文">
          <a-input v-model="baseConfig.reportLink" placeholder="配置新生大数据推文地址，没有则不展示" style="width: 350px;" />
        </a-form-item>
        <a-form-item :wrapper-col="{ offset: 5 }">
          <a-button type="primary" @click="saveBaseConfig">保存</a-button>
          <a-button style="margin-left: 20px;" @click="reset">重置</a-button>
        </a-form-item>
      </a-form>
    </div>
    <div class="upload-box">
      <upload></upload>
      <div class="case">
        <p class="case-tip">注意：上传数据文件必须包含【学号、姓名、性别、学院、录取专业、省份】等信息，其他字段均为非必须</p>
        <img src="../assets/upload_data.png" alt="" style="width: 90%">
      </div>
    </div>
  </div>
</template>

<script>
import Upload from '../components/upload.vue'

export default {
  components: {
    Upload
  },
  data () {
    return {
      baseConfig: {
        year: '', // 新年大数据年份
        promote: { // 用户信息栏链接
          label: '',
          link: ''
        },
        reportLink: '' // 新生大数据推文地址
      }
    }
  },
  mounted () {
    this.$api.report.getConfig({ type: 'baseConfig' }).then(res => {
      if (res.code === 0) {
        if (res.data[0]) {
          this.baseConfig = res.data[0].data
        }
      }
    })
  },
  computed: {
    userInfo () {
      return this.$store.state.userInfo
    }
  },
  methods: {
    saveBaseConfig () {
      const year = this.baseConfig.year
      if (!year) {
        this.$message.error('年份信息不能为空！')
        return
      }
      const { label, link } = this.baseConfig.promote
      if (!label || !link) {
        this.$message.error('信息栏链接配置不能为空！')
        return
      }
      const params = {
        type: 'baseConfig',
        data: this.baseConfig,
        updateUser: this.userInfo.yb_realname,
        updateUserNo: this.userInfo.yb_userid
      }
      this.$api.report.updateConfig(params).then(res => {
        if (res.code === 0) {
          this.$message.success('基础配置保存成功！')
        }
      })
    },
    reset () {
      this.baseConfig = {
        year: '', // 新年大数据年份
        promote: { // 用户信息栏链接
          label: '',
          link: ''
        },
        reportLink: '' // 新生大数据推文地址
      }
    }
  }
}
</script>

<style scoped>
  .wrapper {
    display: flex;
  }
  .theme {
    width: 700px;
  }
  .upload-box{
    margin-left: 15px;
  }
  .case {
    margin: 15px 0;
  }
</style>
